home *** CD-ROM | disk | FTP | other *** search
- Path: doc.ic.ac.uk!brj
- From: brj@doc.ic.ac.uk (Benjamin Jefferys)
- Newsgroups: comp.lang.c++
- Subject: Problem with generic classes/templates
- Date: 18 Jan 1996 12:35:55 -0000
- Organization: Dept. of Computing, Imperial College, University of London, UK.
- Distribution: world
- Message-ID: <4dlerb$r3r@finch.doc.ic.ac.uk>
- Reply-To: brj@doc.ic.ac.uk (Benjamin Jefferys)
- NNTP-Posting-Host: finch.doc.ic.ac.uk
- X-Newsreader: mxrn 6.18-23
-
-
-
- Right. I've declared a generic class which contains a definition of
- another class which has a constructor function which requires arguments.
- My terminology is probably a bit dodgy, so here is an outline:
-
- class meringue{
- int ann;
- float veronica;
- public:
- meringue(int fred, float john) { ann=fred; veronica=john; }
- };
-
- template <class X> class marzipan<X>{
- X ian;
- public:
- marzipan<X>(/* what goes here? */) { /* and what goes here? */ }
- }
-
- Once I've got these, I try a:
-
- marzipan<meringue> bob;
-
- But how do I pass parameters to the constructor function of meringue?
- The way you do it with inherited functions is to pass them to the
- constructor function of the derived class, then give them to the bases
- from there. But how do I do this here - I have to cater for all possible
- Xs, which could take any number/type of parameters (or none at all).
- How do I do this? I understand that I can use "..." somehow, but my
- C++ book seems to skip over this, only saying that it exists if you want to
- pass variable numbers/types of parameters to a function, and that you need
- at least one properly defined parameter (eg. int function(int roger, ...); )
-
- But how do you access the parameters that are passed? Is there another
- more elegant solution to my problem?
-
- (As a matter of interest, the generic class(es) implements a doubly-linked
- list, which obviously has to store any class to be useful)
-
- Thanks in advance for your help.
-
- Bye!
-
- --
-
- My name is BEN.
-